﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Drawing;
using EmbeddedSharp.Core;

namespace Zove.Desktop {
    public sealed class DesktopFormContext : Dictionary<string, Form> {
        private static DesktopFormContext context = new DesktopFormContext();

        private DesktopFormContext() {
            BreakPoints = new List<BreakPoint>();
        }

        public static DesktopFormContext Context {
            get {
                return context;
            }
        }

        public void Add(Form form) {
            if (this.ContainsKey(form.Text)) {
                this[form.Text] = form;
            } else {
                this.Add(form.Text, form);
            }
        }

        public Font Font {
            get {
                string fontName = ConfigurationManager.AppSettings["Font"];
                fontName = string.IsNullOrEmpty(fontName) ? "Courier New" : fontName;

                string fontSize = ConfigurationManager.AppSettings["Font-Size"];
                fontSize = string.IsNullOrEmpty(fontSize) ? "10" : fontSize;

                Font font = new Font(fontName, (float)Convert.ToDouble(fontSize));
                return font;
            }
            set {
                ConfigurationManager.AppSettings["Font"] = value.Name;
                ConfigurationManager.AppSettings["Font-Size"] = value.Size.ToString();
            }
        }

        public bool ShowLineNumber {
            get {
                string showLineNumber = ConfigurationManager.AppSettings["Show line number"];
                bool boolShowLineNumber = string.IsNullOrEmpty(showLineNumber) ? true : Convert.ToBoolean(showLineNumber);

                return boolShowLineNumber;
            }
            set {
                ConfigurationManager.AppSettings["Show line number"] = Convert.ToString(value);
            }
        }

        public Form1 Main {
            get;
            set;
        }

        public void Remove(Form form) {
            this.Remove(form.Text);
        }

        public List<BreakPoint> BreakPoints {
            get;
            set;
        }
    }
}
